<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script src="./vue.js"></script>
  <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> -->
  <div id="app">
    <h1>小黑的书架</h1>
    <ul>
      <!-- 添加v-bind:key是为了删除时状态不乱 -->
      <li v-for="item in List" v-bind:key="item.id">
        {{item.name}}{{item.author}}
        <button @click="del(item.id)">删除</button>
      </li>
    </ul>

  </div>
  <script>
    // 创建实例对象
    const app = new Vue({
      // 容器
      el: '#app',
      // 数据
      data: {
        List: [
          { id: 1, name: "《红楼梦》", author: "曹雪芹" },
          { id: 2, name: "《红楼梦2》", author: "曹雪芹" },
          { id: 3, name: "《红楼梦3》", author: "曹雪芹" },
          { id: 4, name: "《红楼梦4》", author: "曹雪芹" }
        ]
      },
      methods: {
        del(id) {
          this.List = this.List.filter(item => item.id !== id)
        }
      }
    })

  </script>
</body>

</html>